<include file="public@header"/>

<link href="__TMPL__/public/assets/themes/{:cmf_get_admin_style()}/bootstrap.min.css" media="all" rel="stylesheet">
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li  class="active"><a href="{:url('NiuCard/index')}">牛牛卡奖学金管理</a></li>
        <li>
            <a href="#" id="new_card" >
                新建
            </a>
        </li>
    </ul>
    <form class="well form-inline margin-top-20 row" method="post" action="{:url('NiuCard/index')}">
        <label class="col-md-3 col-sm-6   form-group" >
            卡号:
            <input type="number" class="form-control" name="card_number"
                   value="{$param.card_number|default=''}" placeholder="">
        </label>
        <label class="col-md-3 col-sm-6  form-group" >
            学生姓名:
            <input type="text" class="form-control" name="tname"
                   value="{$param.tname|default=''}" placeholder="">
        </label>
        <label class="col-md-3 col-xs-6  form-group" style="margin-bottom: 15px;">
            学号:
            <input type="text" class="form-control" name="code" id="code"
                   value="{$param.code|default=''}" placeholder="">
        </label>
        <label class="col-md-3 col-sm-6  form-group">
            状态:
            <select class="form-control" name="is_used" id="is_used">
                <option value="">全部</option>
                <if condition="isset($param.is_used) && $param.is_used==1">
                    <option value="1" selected>绑定</option>
                    <else/>
                    <option value="1">已绑定</option>
                </if>
                <if condition="isset($param.is_used) && $param.is_used!='' && $param.is_used==0">
                    <option value="0" selected>未绑定</option>
                    <else/>
                    <option value="0">未绑定</option>
                </if>
            </select>
        </label>
        <label class="col-md-3 col-sm-6   form-group">
            <input type="submit"  class="btn btn-primary" value="搜索"/>
            <a class="btn btn-danger" href="{:url('NiuCard/index')}">清空</a>
        </label>
    </form>
    <form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('NiuCard/delete')}" data-subcheck="true" data-msg="您确定删除吗？">
                批量删除
            </button>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th width="50">编号</th>
                <th width="100">类型</th>
                <th width="120">卡号</th>
                <th width="100">金额</th>
                <th width="70">家长姓名</th>
                <th width="70">学生姓名</th>
                <th width="70">学生学号</th>
                <th width="70">发放日期</th>
                <th width="70">有效期</th>
                <th width="40">操作人</th>
                <th width="70">绑定</th>
                <th width="70">状态</th>
                <th width="150">操作</th>

            </tr>
            </thead>
            <foreach name="data" item="vo">
                <tr>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td>{$vo.id}</td>
                    <td>
                        <if condition="!empty($vo.card_type) && $vo.card_type==1">
                           牛牛卡
                            <else />
                            奖学金
                        </if>
                    </td>
                    <td>
                        <if condition="!empty($vo.card_type) && $vo.card_type==2">
                            /
                            <else />
                            {$vo.card_number}
                        </if>
                    </td>
                    <td>{$vo.award_money}</td>
                    <td>{$vo.realname}</td>
                    <td>{$vo.tname}</td>
                    <td>{$vo.tcode}</td>
                    <td>
                        {:date('Y-m-d ',$vo.created_time)}
                    </td>
                    <td>
                        <if condition="!empty($vo.card_type) && $vo.card_type==1">
                            永久有效
                            <else />
                            {:date('Y-m-d ',$vo.valid_date)}
                        </if>
                    </td>
                    <td>{$vo.uuuser_login}</td>
                    <td>
                        <if condition="empty($vo.is_used)">
                            <span class="label label-success">未绑定</span>
                            <else />
                            <span class="label label-danger">已绑定</span>
                        </if>
                    </td>
                    <td>
                        <if condition="empty($vo.aoid)">
                            <span class="label label-success">未使用</span>
                            <else />
                            <span class="label label-danger">已使用</span>
                        </if>
                    </td>
                    <td>
                             <a href="{:url('NiuCard/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                        <if condition="!empty($vo.card_type) && $vo.card_type==1 && $vo.is_used eq 0">
                            <a id="ding" data_id="{$vo['id']}" style="cursor: pointer;">绑定家长</a>
                            <elseif condition="!empty($vo.card_type) && $vo.card_type==1 && $vo.is_used eq 1">
                                <a></a>
                            </elseif>
                            <else/>

                        </if>
                    </td>
                </tr>
            </foreach>
        </table>
        <div class="pagination">{$page|default=''}</div>
    </form>
</div>
<div id="card_add_msg"  style="display: none">
    <form action="{:url('NiuCard/addPost')}" method="post" class="well row js-ajax-form " style="margin:0px;">
            <input class="form-control" type="hidden" name="card_type"
                   id="card_type"  value="1" placeholder="" >
        <label class="form-group" for="" id="card_box">
            卡号:<span class="form-required">*</span>
            <input class="form-control" type="text" name="card_number"
                   id="card"  value="" placeholder="请输入卡号" >
        </label>
        <label class="form-group" for="">
            金额:<span class="form-required">*</span>
            <input class="form-control" type="number" name="award_money" required="required" placeholder="请输入金额">
        </label>
        <button type="submit" id="submit" style="display:none;" class="btn btn-primary js-ajax-submit "></button>
    </form>
</div>
<!--绑定家长-->
<div id="card_ding_msg"  style="display: none">
    <form action="{:url('NiuCard/editPost')}" method="post" class="well row js-ajax-form " style="margin:0px;">

        <label class="form-group" for="" id="card_box1">
            手机号:<span class="form-required">*</span>
            <input class="form-control" type="number" name="mobile"
                   id="mobile"  value="" placeholder="请输入手机号" >
        </label>
        <input type="hidden" name="id" value="" id="niu_id">
        <label class="form-group" for="" >
            <p class="btn btn-success" id="search_parent">查询</p>
        </label>
        <br>
        <label class="form-group" for="">
            学生姓名:<span class="form-required">*</span>
            <input class="form-control" type="hidden" name="student_id"
                   id="student_id_parent"  value=""  readonly >

        </label>
        <button type="submit" id="submit1" style="display:none;" class="btn btn-primary js-ajax-submit "></button>
    </form>
</div>

<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/layer/layer.js"></script>
<script>
    $(function()
    {
        $('#valid_date').datepicker();
        $("body").on("click",'#new_card',function()
            {
                var $card_type=$("[name='card_type']").val();
                var $card=$("[name='card']").val();
                var $amount=$("[name='amount']").val();
                var $student_id=$("[name='student_id']").val();
                var valid_date=$("[name='valid_date']").val();
                $('input').blur(function ()
                {
                    $card_type=$("[name='$card_type']").val();
                    $card=$("[name='card']").val();
                    $amount=$("[name='amount']").val();
                    $student_id=$("[name='student_id']").val();
                })
                layer.open
                ({
                    type: 1,
                    btn: ['提交'],
                    title: '新建牛牛卡',
                    content: $('#card_add_msg'),
                    yes: function (index,layero)
                    {
                        $('#submit').click();
                    }
                })
             })
        $('body').on('change','#card_type',function()
        {
            $type=$(this).find("option:selected").val();
            if($type==1)
            {
                if($("#card_box").is(":hidden"))
                {
                    $("#card_box").show();
                }
                if($("#valid_date_box").is(":visible"))
                {
                    $("#valid_date_box").hide();
                }
            }
            else if($type==2)
            {
                if($("#card_box").is(":visible"))
                {
                    $("#card_box").hide();
                }
                if($("#valid_date_box").is(":hidden"))
                {
                    $("#valid_date_box").show();
                }
            }

        })
//绑定家长用户
        $("body").on("click",'#ding',function()
        {
            var data_id=$(this).attr('data_id');
           $("#mobile").val();
            $("#niu_id").val();
            $("#niu_id").val(data_id);
            layer.open
            ({
                type: 1,
                btn: ['提交'],
                title: '绑定牛牛卡',
                content: $('#card_ding_msg'),
                yes: function (index,layero)
                {
                    $('#submit1').click();
                }
            })
        })
        //查询家长用户

        $("body").on("click",'#search_parent',function(){
            mobile=$("#mobile").val();
            $(".search_student").remove();
            $("#student_id_parent").val('');


            if(mobile==''){return false;}
            //助学金的动态
            $.ajax({
                url: "{:url('financial/NiuCard/ajax_user')}",
                type: 'get',
                data: {'mobile': mobile},
                success: function (data) {
                    data1 = jQuery.parseJSON(data);
                    console.log(data1);
                    for(var i in data1)
                    {
                        $("<br><span class='search_student'>"+data1[i].name+"</span><br>").insertAfter("#student_id_parent");
                        uid=data1[i].u_id;
                    }
                    console.log(uid);
                    $("#student_id_parent").val(uid);
                }
            })
        })
    })
</script>
</body>
